home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / mach / amiga / scsi9091.lzh / int_handler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-24  |  3.0 KB  |  137 lines

  1. #include <exec/types.h>
  2. #include <exec/execbase.h>
  3. #include <exec/nodes.h>
  4. #include <exec/resident.h>
  5. #include <exec/errors.h>
  6. #include <libraries/expansionbase.h>
  7. #include <libraries/configvars.h>
  8. #include <devices/trackdisk.h>
  9. #include <hardware/intbits.h>
  10.  
  11. /*
  12.  * Set SysBase to a local variable, that loads directly from 4 when it
  13.  * has to be reloaded
  14.  */
  15. #define BASE_EXT_DECL
  16. #define BASE_NAME (*(void **)4)
  17. #include <inline/exec.h>
  18.  
  19. #include "device.h"
  20.  
  21. struct int_data {
  22.   struct Task *sig_task;
  23.   long sig_mask;
  24.   long signal;
  25.   volatile ubyte *board;
  26. };
  27.  
  28. /*
  29.  * interrupt handlers for the device. You can have "real" interrupts
  30.  * or have those functions poll for the event. You should normally use
  31.  * real interrupts. (besides, the pollin on the 2091 won't work, because
  32.  * I don't have documentation for it:-()
  33.  */
  34.  
  35. extern ulong read_scsi_reg (volatile ubyte *board, ulong reg_num);
  36.  
  37. /* only needed, if the code is in assembler.. (no more:-)) */
  38. extern int int_code ();
  39.  
  40. void
  41. install_int_handler (struct scsi_dev *dev)
  42. {
  43. #ifdef REAL_INT
  44.   dev->id_sig_task = FindTask(0);
  45.   dev->id_signal = AllocSignal(-1);
  46.   dev->id_sig_mask = 1 << dev->id_signal;
  47.   dev->id_board = (volatile ubyte *)dev->sc_base;
  48.   
  49.   /* has to be in front of hddisk.device or scsi.device
  50.    * this can be reset to 0 when we never again will "overlay" a running
  51.    * device :-))) */
  52.   dev->sc_iv.is_Node.ln_Pri = 30;
  53.   dev->sc_iv.is_Node.ln_Type = NT_INTERRUPT;
  54.   dev->sc_iv.is_Node.ln_Name = SCSI_NAME;
  55.   
  56.   dev->sc_iv.is_Code = (VOID (*))int_code;
  57.   dev->sc_iv.is_Data = (APTR) &dev->id_sig_task;
  58.   
  59.   AddIntServer(INTB_PORTS, &dev->sc_iv);
  60. #endif
  61. }
  62.  
  63. void
  64. remove_int_handler (struct scsi_dev *dev)
  65. {
  66. #ifdef REAL_INT
  67.   RemIntServer(INTB_PORTS, &dev->sc_iv);
  68.   FreeSignal(dev->id_signal);
  69. #endif
  70. }
  71.  
  72. void
  73. wait_interrupt (struct scsi_dev *dev)
  74. {
  75. #ifdef REAL_INT
  76.   Wait (dev->id_sig_mask);
  77. #else
  78.   while (!(board[A2090_CNTL_LO] & INT_FOLLOW)) ;
  79.   read_scsi_reg (board, WD_SCSI_STATUS);
  80. #endif
  81. }
  82.  
  83. void
  84. clear_interrupt (struct scsi_dev *dev)
  85. {
  86. #ifdef REAL_INT
  87.   SetSignal(0, dev->id_sig_mask);
  88. #endif
  89. }
  90.  
  91. #ifdef REAL_INT
  92. #ifdef A2090
  93. static int
  94. int_code ()
  95. {
  96.   register struct int_data *id_pass asm("a1");
  97.   register struct int_data *idi = id_pass;
  98.   int i; 
  99.  
  100.   if (idi->board[A2090_CNTL_LO] & INT_FOLLOW)
  101.     {
  102.       read_scsi_reg (idi->board, WD_SCSI_STATUS);
  103.       Signal (idi->sig_task, idi->sig_mask);
  104. /* for (i=0; i<10; i++) *(unsigned short *)0xdff180 = 0; */
  105.       return 1;
  106.     }
  107.   return 0;
  108. }
  109. #endif
  110. #ifdef A2091
  111. static int
  112. int_code ()
  113. {
  114.   register struct int_data *id_pass asm("a1");
  115.   register struct int_data *idi = id_pass;  /* id_pass;*/
  116.   int i; 
  117.  
  118. /*  for (i=0; i<10; i++) *(unsigned short *)0xdff180 = 0; */
  119.  
  120.   if (idi->board[0x41] & (1 << 4))
  121.     {
  122.       if (idi->board[0x41] & (1 << 5)) *(ushort *)&idi->board[0xe4] = 0;
  123.  
  124.       if (idi->board[0x41] & (1 << 6))
  125.     {
  126.       read_scsi_reg (idi->board, WD_SCSI_STATUS);
  127.  
  128.       if (idi->board[0xa3] & (1 << 5)) idi->board[0xa7] = 0;
  129.       Signal(idi->sig_task, idi->sig_mask);
  130.     }
  131.       return 1;
  132.     }
  133.   return 0;
  134. }
  135. #endif
  136. #endif
  137.